home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_313 / uucp / uucp1.lzh / src / lib / getenv.c < prev    next >
C/C++ Source or Header  |  1990-01-10  |  834b  |  59 lines

  1.  
  2. /*
  3.  *  GETENV.C
  4.  *
  5.  *  Lattice's screws up.
  6.  *
  7.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  8.  */
  9.  
  10. #include <proto/all.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14. char *
  15. gettmpenv(id)
  16. char *id;
  17. {
  18.     static char *buf;
  19.     static char *res = NULL;
  20.     long fh;
  21.     long len;
  22.  
  23.     buf = malloc(strlen(id) + 8);
  24.     sprintf(buf, "ENV:%s", id);
  25.     fh = Open(buf, 1005);
  26.     free(buf);
  27.     if (fh) {
  28.     Seek(fh, 0L, 1);
  29.     len = Seek(fh, 0L, -1);
  30.     if (len < 0) {
  31.         Close(fh);
  32.         return(NULL);
  33.     }
  34.     if (res)
  35.         free(res);
  36.     res = malloc(len + 1);
  37.     Read(fh, res, len);
  38.     Close(fh);
  39.     res[len] = 0;
  40.     return(res);
  41.     }
  42.     return(NULL);
  43. }
  44.  
  45. char *
  46. getenv(id)
  47. char *id;
  48. {
  49.     char *res = gettmpenv(id);
  50.     char *perm = NULL;
  51.  
  52.     if (res) {
  53.     perm = malloc(strlen(res) + 1);
  54.     strcpy(perm, res);
  55.     }
  56.     return(perm);
  57. }
  58.  
  59.